package com.aspose.cells;

class zyd {
   private WorksheetCollection a;
   private zabe b;
   private zaas c;
   private zbwb d;
   private zces e;

   zabe a() {
      return this.b;
   }

   static byte[] a(WorksheetCollection var0, WorksheetCollection var1, byte[] var2, int var3, int var4, int var5) {
      if (var2 == null) {
         return null;
      } else {
         byte[] var6 = null;
         if (var0.n().i() == var1.n().i()) {
            var6 = new byte[var2.length];
            System.arraycopy(var2, 0, var6, 0, var2.length);
            return var6;
         } else {
            switch(var0.n().i()) {
            case 0:
               switch(var1.n().i()) {
               case 0:
               default:
                  return var6;
               case 1:
                  var6 = zcq.a(var2, var3, var4, var5, false);
                  return var6;
               }
            case 1:
               switch(var1.n().i()) {
               case 0:
                  var6 = zcr.a(var2, var3);
               case 1:
               }
            }

            return var6;
         }
      }
   }

   zyd(WorksheetCollection var1) {
      this.a = var1;
      this.c = new zaas(this.a);
      this.b = new zabe(this.a);
      this.d = new zbwb(this.a);
      this.e = new zces(this.a);
   }

   byte[] a(String var1, String[] var2, Cell var3) {
      if (var1.charAt(0) != '=') {
         throw new CellsException(5, "Invalid function format.");
      } else {
         zabd var4 = this.a(var1);
         if (var4.i() != 3) {
            throw new CellsException(5, "Invalid function format.");
         } else {
            var4.a(4);
            var2[0] = var4.b();
            byte[] var5 = this.b.a(var4, this.a, var3.d.h().getIndex(), 0, 0, 0, 64, 0, false);
            byte[] var6 = new byte[var5.length + 7];
            var6[0] = 57;
            System.arraycopy(var5, 0, var6, 7, var5.length);
            return var6;
         }
      }
   }

   boolean b() {
      return this.b.a();
   }

   byte[] a(int var1, String var2, int var3, int var4, int var5, int var6, boolean var7, boolean var8, boolean var9) {
      try {
         zabd var10 = this.a(var2);
         return this.b.a(var10, this.a, var1, var3, var4, zabe.a(var7, var9), var6, var5, var8);
      } catch (Exception var11) {
         throw new CellsException(5, var11.getMessage() + "\"" + var2 + "\".");
      }
   }

   void a(Cell var1, String var2, byte var3, boolean var4) {
      byte var5 = 1;
      if (var2.charAt(0) != '=') {
         var5 = 0;
      }

      try {
         zabd var6 = this.c.a(var2, var5);
         byte[] var7 = this.b.a(var6, this.a, var1.d.h().getIndex(), var1.getRow(), var1.getColumn(), var3 & 255, 64, 0, true);
         zyi var8 = new zyi(var1.getRow(), var1.getColumn());
         var8.b = var7;
         var1.a(var8);
      } catch (Exception var9) {
         throw new CellsException(5, "Error in Cell: " + var1.getName() + "-" + var9.getMessage() + "\"" + var2 + "\".");
      }
   }

   byte[] a(int var1, int var2, int var3, String var4, byte var5) {
      if (var4.charAt(0) != '=') {
         throw new CellsException(5, "Invalid formula:\"" + var4 + "\".");
      } else {
         try {
            zabd var6 = this.a(var4);
            return this.b.a(var6, this.a, var1, var2, var3, var5 & 255, 64, 0, true);
         } catch (Exception var7) {
            throw new CellsException(5, "Error in Cell: " + CellsHelper.cellIndexToName(var2, var3) + "-" + var7.getMessage() + "\"" + var4 + "\".");
         }
      }
   }

   void a(Cell var1, String var2, int var3, int var4) {
      if (var2.charAt(0) != '=') {
         throw new CellsException(5, "Invalid formula:\"" + var2 + "\".");
      } else {
         zabd var5 = this.a(var2);
         byte[] var6 = this.b.a(var5, this.a, var1.d.h().getIndex(), var1.getRow(), var1.getColumn(), 0, 64, 1, true);
         CellArea var7 = new CellArea();
         var7.StartRow = var1.getRow();
         var7.StartColumn = var1.getColumn();
         var7.EndRow = var1.getRow() + var3 - 1;
         var7.EndColumn = var1.getColumn() + var4 - 1;
         zaz var8 = new zaz(var7, true, var6);
         var6 = this.b.a((byte)1, var1.getRow(), var1.getColumn());
         zyj var9 = new zyj(var1.getRow(), var1.getColumn(), var8);
         var9.b = var6;
         var1.a((zyi)var9);
      }
   }

   zabd a(String var1) {
      byte var2 = 1;
      if (var1.charAt(0) != '=') {
         var2 = 0;
      }

      return this.c.a(var1, var2);
   }

   void b(Cell var1, String var2, int var3, int var4) {
      if (var2.charAt(0) != '=') {
         throw new CellsException(5, "Invalid formula:\"" + var2 + "\".");
      } else {
         try {
            zabd var5 = this.a(var2);
            byte[] var6 = this.b.a(var5, this.a, var1.d.h().getIndex(), var1.getRow(), var1.getColumn(), 1, 64, 0, true);
            CellArea var7 = new CellArea();
            var7.StartRow = var1.getRow();
            var7.StartColumn = var1.getColumn();
            var7.EndRow = var1.getRow() + var3 - 1;
            var7.EndColumn = var1.getColumn() + var4 - 1;
            zaz var8 = new zaz(var7, false, var6);
            var6 = this.b.a((byte)1, var1.getRow(), var1.getColumn());
            zyj var9 = new zyj(var1.getRow(), var1.getColumn(), var8);
            var9.b = var6;
            var1.a((zyi)var9);
         } catch (Exception var10) {
            throw new CellsException(5, "Error in Cell: " + var1.i() + "-" + var10.getMessage() + "\"" + var2 + "\".");
         }
      }
   }

   zabd a(Name var1, Cell var2) {
      if (var1.b() != null) {
         return this.a(var2, var1.b(), -1);
      } else if (var1.getRefersTo() != null) {
         zabd var3 = this.a(var1.getRefersTo());
         this.b.a(var3, this.a, -1, 0, 0, 0, 64, 2, true);
         return var3;
      } else {
         return null;
      }
   }

   zabd b(Name var1, Cell var2) {
      zabd var3;
      if (var1.b() != null) {
         if (this.a.n().k()) {
            this.e.b = true;
            var3 = this.e.a(var2, var1.b(), -1);
            this.e.b = false;
            return var3;
         } else {
            return this.d.a(var2, var1.b(), -1);
         }
      } else {
         var3 = this.a(var1.getRefersTo());
         this.b.a(var3, this.a, -1, 0, 0, 0, 64, 2, true);
         return var3;
      }
   }

   zabd a(Cell var1) {
      if (var1.v() != null) {
         return this.a(var1, (byte[])null, -1);
      } else {
         throw new CellsException(5, "Unsupported formula in cell " + var1.i() + ":\"" + var1.getFormula() + "\".");
      }
   }

   zabd a(Cell var1, byte[] var2, int var3) {
      return this.a.n().k() ? this.e.a(var1, var2, var3) : this.d.a(var1, var2, var3);
   }

   boolean c() {
      return this.a.n().k() ? this.e.a : this.d.a;
   }

   boolean a(byte var1, byte[] var2) {
      if (this.a.n().k()) {
         int var3 = com.aspose.cells.b.a.zc.a(var2, 0);
         return var3 == 7 && var2[4] == var1;
      } else {
         return var2[0] == 5 && var2[2] == var1;
      }
   }

   void a(byte[] var1, int[] var2, int[] var3) {
      if (this.a.n().k()) {
         var2[0] = com.aspose.cells.b.a.zc.a(var1, 5);
         var3[0] = zcew.a(var1, 9);
      } else {
         var2[0] = com.aspose.cells.b.a.zc.e(var1, 3) & '\uffff';
         var3[0] = var1[5] & 255;
      }

   }

   static void a(Object var0, Cell var1) {
      CellArea var2 = var1.D().a();
      Cells var3 = var1.d;
      Cell var4 = null;
      int var6;
      int var12;
      if (var0 == null) {
         if (var2.StartRow == var2.EndRow && var2.StartColumn == var2.EndColumn) {
            var4 = var3.a(var2.StartRow, var2.StartColumn, false);
            var4.a((Object)zml.g, (byte)2);
         } else {
            for(var12 = var2.StartRow; var12 <= var2.EndRow; ++var12) {
               for(var6 = var2.StartColumn; var6 <= var2.EndColumn; ++var6) {
                  var4 = var3.a(var12, var6, false);
                  var4.a((Object)zst.c, (byte)2);
               }
            }

         }
      } else if (!com.aspose.cells.a.c.zc.a(var0)) {
         for(var12 = var2.StartRow; var12 <= var2.EndRow; ++var12) {
            for(var6 = var2.StartColumn; var6 <= var2.EndColumn; ++var6) {
               var4 = var3.a(var12, var6, false);
               var4.a((Object)var0, (byte)2);
            }
         }

      } else {
         Object[] var5 = (Object[])((Object[])var0);

         int var7;
         for(var6 = 0; var6 < var5.length && var2.StartRow + var6 <= var2.EndRow; ++var6) {
            var7 = var2.StartRow + var6;
            Object var8 = com.aspose.cells.b.a.za.a(var5, var6);
            if (var8 == null) {
               for(int var9 = var2.StartColumn; var9 <= var2.EndColumn; ++var9) {
                  var4 = var3.a(var7, var9, false);
                  var4.a((Object)zst.c, (byte)2);
               }
            } else if (com.aspose.cells.a.c.zc.a(var8)) {
               Object[] var13 = (Object[])((Object[])var8);

               int var10;
               for(var10 = 0; var10 < var13.length && var2.StartColumn + var10 <= var2.EndColumn; ++var10) {
                  var4 = var3.a(var7, var2.StartColumn + var10, false);
                  Object var11 = com.aspose.cells.b.a.za.a(var13, var10);
                  var4.a((Object)var11, (byte)2);
               }

               if (var2.EndColumn - var2.StartColumn + 1 > var13.length) {
                  for(var10 = var2.StartColumn + var13.length; var10 <= var2.EndColumn; ++var10) {
                     var4 = var3.a(var7, var10, false);
                     var4.a((Object)zst.c, (byte)2);
                  }
               }
            }
         }

         if (var5.length < var2.EndRow - var2.StartRow + 1) {
            for(var6 = var2.StartRow + var5.length; var6 <= var2.EndRow; ++var6) {
               for(var7 = var2.StartColumn; var7 <= var2.EndColumn; ++var7) {
                  var4 = var3.a(var6, var7, false);
                  var4.a((Object)zst.c, (byte)2);
               }
            }
         }

      }
   }
}
